﻿//  -------------------- iSharePoint -------------------- //
// 
//  Company:	IT Complex, LLC
//  Project:	Smart.Common
//  File name:	FormsRuleExecutor.cs
//  Developer:	Solomatov Igor
//  Created:	15.04.2012
// 
//  -------------------- iSharePoint -------------------- //

using System;
using Smart.Common.Rules;

namespace Smart.Common.Forms
{
	public class FormsRuleExecutor : XmlRuleExecutor
	{
		public FormsRuleExecutor(RulesCtx ctx)
			: base(ctx)
		{
		}

		public override bool ApplyAction(XmlRuleActionMethod action)
		{
			var cri = Ctx.Instance as FormsChooseRulesInstance;

			if (cri != null)
			{
				cri.ChoosedFormName = action.Name;

				Ctx.StopRulesProcessing = true;

				return true;
			}

			var ari = Ctx.Instance as FormsActionRulesInstance;

			if (ari != null)
			{
				return ari.Ctx.Service.Formatter.PerformAction(action.Name, action.Parameters);
			}

			throw new NotSupportedException();
		}
	}
}